import allure
#导入和该业务有关的页面类
from page.page_index import PageIndex
from page.page_login import PageLogin
from page.page_user import PageUser

#登录业务
class ServiceLogin(object):
    def __init__(self,driver,base_url):
        self.driver=driver
        self.base_url=base_url

        #初始化页面对象
        self.page_index=PageIndex(self.driver,self.base_url)
        self.page_login=PageLogin(self.driver,self.base_url)
        self.page_user=PageUser(self.driver,self.base_url)


    def service_login_001(self,d):
        #接受测试数据
        key=d["key"]
        zanhao=d["zanhao"]
        pwd=d["pwd"]
        yuqi=d["yuqi"]
        #UI1上的操作
        allure.attach("","步骤1：打开首页")
        self.page_index.openUrl()
        allure.attach("", "步骤2：点击“首页”上面的登录按钮")
        self.page_index.click_login()

        #UI2上的操作
        allure.attach("", f"步骤3：输入账号:{zanhao}")
        self.page_login.inputZanhao(zanhao)
        allure.attach("", f"步骤4：输入密码:{pwd}")
        self.page_login.inputPwd(pwd)
        self.page_login.click_login()


        #UI3上的操作
        siji=self.page_user.getH2Text() #"zaoliu，欢迎光临"
        imgName=self.page_user.savePng3("登录业务",key) #"登录业务_K001_20240507093001"
        allure.attach(open(f'./screen/{imgName}.png', 'rb').read(), "步骤5:本次截图", allure.attachment_type.PNG)
        return yuqi in siji


    def service_login_002(self,d):
        #接受测试数据
        key=d["key"]
        zanhao=d["zanhao"]
        pwd=d["pwd"]
        yuqi=d["yuqi"]
        #UI1上的操作
        self.page_index.openUrl()
        self.page_index.click_login()

        #UI2上的操作
        self.page_login.inputZanhao(zanhao)
        self.page_login.inputPwd(pwd)
        self.page_login.click_login()

        #UI3上的操作
        siji=self.page_login.getErrorTips() #"账号或密码错误"
        imgName = self.page_user.savePng3("登录业务", key)  # "登录业务_K001_20240507093001"
        allure.attach(open(f'./screen/{imgName}.png', 'rb').read(), "本次截图", allure.attachment_type.PNG)
        return yuqi in siji

    def service_login_003(self,d):
        #接受测试数据
        key=d["key"]
        zanhao=d["zanhao"]
        pwd=d["pwd"]
        yuqi=d["yuqi"]
        #UI1上的操作
        self.page_index.openUrl()
        self.page_index.click_login()

        #UI2上的操作
        self.page_login.inputZanhao(zanhao)
        self.page_login.inputPwd(pwd)
        self.page_login.click_login()


        #UI3上的操作
        siji=self.page_login.getPwdClassAttr()
        return yuqi in siji

    def service_login_004(self,d):
        #接受测试数据
        key=d["key"]
        zanhao=d["zanhao"]
        pwd=d["pwd"]
        yuqi=d["yuqi"]
        #UI1上的操作
        self.page_index.openUrl()
        self.page_index.click_login()

        #UI2上的操作
        self.page_login.inputZanhao(zanhao)
        self.page_login.inputPwd(pwd)
        self.page_login.click_login()


        #UI3上的操作
        siji=self.page_login.getZanhaoClassAttr()
        return yuqi in siji


